package no.uials.distsys;

/**
 *
 * @author Anders
 */
public class Article implements java.io.Serializable, Comparable<Article> {
    private String ID;
    private String name;
    private double price;
    private int stock;
    private Position position;

    /**
     * Makes a new Article and gives it a Position in the Warehouse.
     * 
     * @param ID the Article ID.
     * @param name the Article name.
     * @param price the Article price.
     * @param stock the number of Articles.
     * @param pos the Position of the Article.
     */
    public Article(String ID, String name, double price, int stock, Position pos) {
        this.ID = ID;
        this.name = name;
        this.price = price;
        this.stock = stock;
        position = pos;
    }
    
    /**
     * Makes a new Article and gives it a Position in the Warehouse.
     * 
     * @param ID the Article ID.
     * @param name the Article name.
     * @param price the Article price.
     * @param stock the number of Articles.
     * @param aisle the aisle in whitch the Article will be placed.
     * @param section the section in whitch the Article will be placed.
     * @param shelf the shelf in whitch the Article will be placed.
     */
    public Article(String ID, String name, double price, int stock, int aisle, int section, int shelf) {
        this(ID, name, price, stock, new Position(aisle, section, shelf));
    }

    /**
     * Returns the ID of the Article.
     * 
     * @return the Article ID.
     */
    public String getID() {
        return ID;
    }

    /**
     * Returns the name of the Article.
     * 
     * @return the Article name.
     */
    public String getName() {
        return name;
    }
    
    /**
     * Sets a new name to the Article.
     * 
     * @param newName the new name.
     * @return the new name.
     */
    public String setName(String newName) {
        return name = newName;
    }

    /**
     * Returns the Position of the Article.
     * 
     * @return the Article's Position.
     */
    public Position getPosition() {
        return position;
    }
    

    /**
     * Returns the unit price for the Article.
     * 
     * @return the unit Price.
     */
    public double getPrice() {
        return price;
    }

    /**
     * Returns the number of available units of the Article.
     * 
     * @return the stock.
     */
    public int getStock() {
        return stock;
    }
    
    /**
     * Changes the unit price for the Article.
     * 
     * @param newPrice the new price.
     * @return the new price.
     */
    public double changePrice(double newPrice) {
        return price = newPrice;
    }
    
    /**
     * Changes the Position of the Article.
     * 
     * @param pos the new Position.
     * @return the new Position.
     */
    public Position changePosition(Position pos) {
        return position = pos;
    }
    
    /**
     * Changes the Position of the Article.
     * 
     * @param aisle the new aisle.
     * @param section the new section.
     * @param shelf the new shelf.
     * @return the new Position.
     */
    public Position changePosition(int aisle, int section, int shelf) {
        return changePosition(new Position(aisle, section, shelf));
    }
    
    /**
     * Adds the given to the number of currently available units of the Article.
     * 
     * @param number the number of units to add to the current stock.
     * @return the new number of available units of the Article.
     */
    public int changeStock(int number) {
        if (stock + number <= 0) {
            stock = 0;
        } else {
            stock += number;
        }
        return stock;
    }
    
    /**
     * Sets the number of available units of the Article to the given number.
     * 
     * @param number the given number.
     * @return the new number of available units of the Article.
     */
    public int setStock(int number) {
        return stock = number;
    }
    
    /**
     * Compares the given Article to this Article, in terms of the ID.
     * 
     * @param o the Article to compare to.
     * @return the difference of the Articles as an integer.
     */
    @Override
    public int compareTo(Article o) {
        return ID.compareTo(o.ID);
    }
}